const path = require('path')

const resolve = dir => {
    return path.join(__dirname, dir)
}
console.log(process.env.NODE_ENV ,)
const BASE_URL = process.env.NODE_ENV === 'production' ? './' : '/'

module.exports = {
    // 项目部署的基础路径
    publicPath: BASE_URL,
    // 将构建好的文件输出到哪里
    outputDir: 'dist',
    //css js fonts文件夹位置，必须放到static里，部署到tomcat webapps 才生效
    assetsDir: 'static',
    // use the full build with in-browser compiler?
    // https://vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only
    // compiler: false,
    // webpack配置
    // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
    transpileDependencies: ['webpack-dev-server/client'],
    chainWebpack: config => {
        config.entry.app = ["babel-polyfill", './src/main.js'];
        config.resolve.alias
            .set('@', resolve('src'))
            .set('assets', resolve('src/assets'))
            .set('components', resolve('src/components'))
            .set('core', resolve('src/core'));
    },
    configureWebpack: () => {
    },
    // vue-loader 配置项
    // https://vue-loader.vuejs.org/en/options.html
    // vueLoader: {},
    // 生产环境是否生成 sourceMap 文件
    productionSourceMap: true,
    // css相关配置
    css: {
        // 是否使用css分离插件 ExtractTextPlugin
        // extract: true,
        // 开启 CSS source maps?
        sourceMap: false,
        // css预设器配置项
        loaderOptions: {
            postcss: {
                plugins: [
                    require('postcss-px2rem')({ //配置项，详见官方文档
                        remUnit: 192 // 换算的基数(设计：1920 x 1080)
                    })
                ]
            },
            less: {
                modifyVars: {
                    // // 通过less文件覆盖(文件路径为绝对路径)
                    hack: `true; @import "${path.join(__dirname, "/src/assets/style/index.less")}";`
                }
            },
        },
        // 启用 CSS modules for all css / pre-processor files.
        requireModuleExtension: true
    },
    // use thread-loader for babel & TS in production build
    // enabled by default if the machine has more than 1 cores
    parallel: require('os').cpus().length > 1,
    // 是否启用dll
    // See https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#dll-mode
    // dll: false,
    // PWA 插件相关配置
    // see https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
    pwa: {
        iconPaths: {
            favicon32     : 'favicon.ico',
            favicon16     : 'favicon.ico',
            appleTouchIcon: 'favicon.ico',
            maskIcon      : 'favicon.ico',
            msTileImage   : 'favicon.ico'
        }
    },
    // webpack-dev-server 相关配置
    devServer: {
        open: process.platform === 'darwin',
        host: '0.0.0.0',
        port: 8080,
        https: false,
        hotOnly: true,
        proxy: null, // 设置代理
        before: app => { }
    },
    // 第三方插件配置
    pluginOptions: {
        // ...
    }
}